package com.java.demo.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class ReadIO extends Thread {

	private static final String PATH_1 = "/Users/zhangjun/Downloads/img_1";

	private static final String PATH_2 = "/Users/zhangjun/Downloads/img_3";

	private static Queue<Integer> QUEUE = new ConcurrentLinkedQueue<>();

	public static File getFile(String path) {
		return new File(path);
	}

	public static void CopyFile() throws IOException {
		InputStream is = new FileInputStream(ReadIO.getFile(PATH_1));
		while (is.read() >= 0 && QUEUE.size() < 10) {
			QUEUE.add(is.read());
		}
		is.close();
	}

	@Override
	public void run() {
		try {
			ReadIO.CopyFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		System.out.println(fun(36));
	}

	private static int fun(int n) {
		System.out.println("n=" + n);
		if (n == 1 || n == 2) {
			return 1;
		} else {
			int a = fun(n - 1);
			System.out.println("a=" + a);
			int b = fun(n - 2);
			System.out.println("b=" + b);
			int i = a + b;
			System.out.println("i=" + i);
			return i;
		}
	}
}
